Mark orientable widgets with the vertical/horizontal css classes
authorCarlos Garnacho <carlosg@gnome.org>
Mon, 10 Jan 2011 22:38:47 +0000 (23:38 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Mon, 10 Jan 2011 22:53:29 +0000 (23:53 +0100)
This can be used to theme widgets differently depending on the
orientation. BugĀ 639157, reported by Christian Dywan.

gtk/gtkorientable.c
gtk/gtkstylecontext.h

index dfc0dd6faa8677303231739930e5cbee3c825a13..d3627252fb416c3a39c3b6dee6a529727a8c9eef 100644 (file)
@@ -80,11 +80,29 @@ void
 gtk_orientable_set_orientation (GtkOrientable  *orientable,
                                 GtkOrientation  orientation)
 {
+  GtkStyleContext *context;
+
   g_return_if_fail (GTK_IS_ORIENTABLE (orientable));
 
   g_object_set (orientable,
                 "orientation", orientation,
                 NULL);
+
+  if (GTK_IS_WIDGET (orientable))
+    {
+      context = gtk_widget_get_style_context (GTK_WIDGET (orientable));
+
+      if (orientation == GTK_ORIENTATION_HORIZONTAL)
+        {
+          gtk_style_context_add_class (context, GTK_STYLE_CLASS_HORIZONTAL);
+          gtk_style_context_remove_class (context, GTK_STYLE_CLASS_VERTICAL);
+        }
+      else
+        {
+          gtk_style_context_add_class (context, GTK_STYLE_CLASS_VERTICAL);
+          gtk_style_context_remove_class (context, GTK_STYLE_CLASS_HORIZONTAL);
+        }
+    }
 }
 
 /**
index 00836d6aa3bcdb035836631be9a279b92a047d23..291b8a77f3fa1a6b0e98aab074ad7131a4ec271b 100644 (file)
@@ -399,6 +399,20 @@ struct _GtkStyleContextClass
  */
 #define GTK_STYLE_CLASS_ERROR "error"
 
+/**
+ * GTK_STYLE_CLASS_HORIZONTAL:
+ *
+ * A widget class for horizontally layered widgets.
+ */
+#define GTK_STYLE_CLASS_HORIZONTAL "horizontal"
+
+/**
+ * GTK_STYLE_CLASS_VERTICAL:
+ *
+ * A widget class for vertically layered widgets.
+ */
+#define GTK_STYLE_CLASS_VERTICAL "vertical"
+
 
 /* Predefined set of widget regions */